/*
 * @lc app=leetcode.cn id=36 lang=javascript
 *
 * [36] 有效的数独
 */

// @lc code=start
/**
 * @param {character[][]} board
 * @return {boolean}
 */
var isValidSudoku = function (board) {
  // let hashRow = {}
  // let hashCol = {}
  // let hashBox = {}
  // let len = board.length
  // for (let i = 0; i < len; i++) {
  //   for (let j = 0; j < len; j++) {
  //     const row = board[i][j]
  //     const col = board[j][i]
  //     const box = board[(j / 3 | 0) + (i / 3 | 0) * 3][(j % 3 | 0) + (i % 3 | 0) * 3]
  //     // console.log((j / 3 | 0) + (i / 3 | 0) * 3 + ',' + ((j % 3 | 0) + (i % 3 | 0) * 3))
  //     if (row !== '.') {
  //       if (hashRow[row] !== undefined) {
  //         return false
  //       }
  //       hashRow[row] = row
  //     }
  //     if (col !== '.') {
  //       if (hashCol[col] !== undefined) {
  //         return false
  //       }
  //       hashCol[col] = col
  //     }
  //     if (box !== '.') {
  //       if (hashBox[box] !== undefined) {
  //         return false
  //       }
  //       hashBox[box] = box
  //     }
  //   }
  //   hashRow = {}
  //   hashCol = {}
  //   hashBox = {}
  // }
  // return true
  for (let i = 0; i < 9; i++) {
    for (let j = 0; j < 9; j++) {
      if (board[i][j] == '.') continue;
      for (let k = 8; k > j; k--)
        if (board[i][j] == board[i][k])
          return false;
      for (let k = 8; k > i; k--)
        if (board[i][j] == board[k][j])
          return false;
      for (let k = i + 1; k % 3 != 0; k++) {
        for (let h = (j / 3 | 0) * 3; h < (j / 3 | 0) * 3 + 3; h++)
          if (board[i][j] == board[k][h])
            return false;
      }
    }
  }
  return true;
}
// console.log(
// isValidSudoku([["5","3",".",".","7",".",".",".","."],["6",".",".","1","9","5",".",".","."],[".","9","8",".",".",".",".","6","."],["8",".",".",".","6",".",".",".","3"],["4",".",".","8",".","3",".",".","1"],["7",".",".",".","2",".",".",".","6"],[".","6",".",".",".",".","2","8","."],[".",".",".","4","1","9",".",".","5"],[".",".",".",".","8",".",".","7","9"]])
// )
// @lc code=end

